package com.configuration;

import com.childguo.oc.Person;
import com.childguo.pojo.Stu;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfig {
    //Bean注入相关，默认以方法名注入
    @Bean
    @ConditionalOnProperty(prefix = "Person",name = {"name", "id"})
    public Person getPerson(@Value("${Person.name}")  String name, @Value("${Person.id}") String id){
        return new Person(id, name);
    }

    @Bean
    @ConditionalOnBean(Person.class)
    public Stu getStu(){
        return new Stu();
    }

}
